package com.rabbit.handler;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zjw
 * @date 2021/6/28 10:22
 */
public class RequestContext {

    static final ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>();

    public static Object get(String key) {
        if (threadLocal.get() == null) {
            return "";
        }
        return threadLocal.get().get(key);
    }

    public static void put(String key, Object val) {
        Map<String, Object> localMap = threadLocal.get();
        if (localMap == null) {
            localMap = new HashMap<>(16);
            threadLocal.set(localMap);
        }
        threadLocal.get().put(key, val);
    }

}
